import mysql.connector

# 连接到MySQL数据库
conn = mysql.connector.connect(
    host='152.136.49.229',  # 数据库主机名
    user='yuyu',  # 数据库用户名
    password='123456',  # 数据库密码
    database='yuyude'  # 数据库名称
)

cursor = conn.cursor()

# 查询每个学生的总分
query = """
SELECT student_id, SUM(score) as total_score
FROM scores
GROUP BY student_id;
"""
cursor.execute(query)

# 获取结果
results = cursor.fetchall()

# 输出学生总分
for row in results:
    print(f"学生ID: {row[0]}, 总分: {row[1]}")

# 关闭数据库连接
cursor.close()
conn.close()
